\doxysection{x\+Stream\+Buffer\+Send\+From\+ISR }
\hypertarget{group__x_stream_buffer_send_from_i_s_r}{}\label{group__x_stream_buffer_send_from_i_s_r}\index{xStreamBufferSendFromISR@{xStreamBufferSendFromISR}}
\doxylink{stream__buffer_8h_source}{stream\+\_\+buffer.\+h}


\begin{DoxyPre}
size\_t xStreamBufferSendFromISR( StreamBufferHandle\_t xStreamBuffer,                                  const void *pvTxData,                                  size\_t xDataLengthBytes,                                  BaseType\_t *pxHigherPriorityTaskWoken );
\end{DoxyPre}


Interrupt safe version of the API function that sends a stream of bytes to the stream buffer.

{\itshape {\bfseries{NOTE}}}\+: Uniquely among Free\+RTOS objects, the stream buffer implementation (so also the message buffer implementation, as message buffers are built on top of stream buffers) assumes there is only one task or interrupt that will write to the buffer (the writer), and only one task or interrupt that will read from the buffer (the reader). It is safe for the writer and reader to be different tasks or interrupts, but, unlike other Free\+RTOS objects, it is not safe to have multiple different writers or multiple different readers. If there are to be multiple different writers then the application writer must place each call to a writing API function (such as x\+Stream\+Buffer\+Send()) inside a critical section and set the send block time to 0. Likewise, if there are to be multiple different readers then the application writer must place each call to a reading API function (such as x\+Stream\+Buffer\+Receive()) inside a critical section and set the receive block time to 0.

Use x\+Stream\+Buffer\+Send() to write to a stream buffer from a task. Use x\+Stream\+Buffer\+Send\+From\+ISR() to write to a stream buffer from an interrupt service routine (ISR).


\begin{DoxyParams}{Parameters}
{\em x\+Stream\+Buffer} & The handle of the stream buffer to which a stream is being sent.\\
\hline
{\em pv\+Tx\+Data} & A pointer to the data that is to be copied into the stream buffer.\\
\hline
{\em x\+Data\+Length\+Bytes} & The maximum number of bytes to copy from pv\+Tx\+Data into the stream buffer.\\
\hline
{\em px\+Higher\+Priority\+Task\+Woken} & It is possible that a stream buffer will have a task blocked on it waiting for data. Calling x\+Stream\+Buffer\+Send\+From\+ISR() can make data available, and so cause a task that was waiting for data to leave the Blocked state. If calling x\+Stream\+Buffer\+Send\+From\+ISR() causes a task to leave the Blocked state, and the unblocked task has a priority higher than the currently executing task (the task that was interrupted), then, internally, x\+Stream\+Buffer\+Send\+From\+ISR() will set \texorpdfstring{$\ast$}{*}px\+Higher\+Priority\+Task\+Woken to pd\+TRUE. If x\+Stream\+Buffer\+Send\+From\+ISR() sets this value to pd\+TRUE, then normally a context switch should be performed before the interrupt is exited. This will ensure that the interrupt returns directly to the highest priority Ready state task. \texorpdfstring{$\ast$}{*}px\+Higher\+Priority\+Task\+Woken should be set to pd\+FALSE before it is passed into the function. See the example code below for an example.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The number of bytes actually written to the stream buffer, which will be less than x\+Data\+Length\+Bytes if the stream buffer didn\textquotesingle{}t have enough free space for all the bytes to be written.
\end{DoxyReturn}
Example use\+: 
\begin{DoxyPre}
// A stream buffer that has already been created.
StreamBufferHandle\_t xStreamBuffer;

void vAnInterruptServiceRoutine( void )
\{
size\_t xBytesSent;
char *pcStringToSend = "{}String to send"{};
BaseType\_t xHigherPriorityTaskWoken = pdFALSE; // Initialised to pdFALSE.

    // Attempt to send the string to the stream buffer.
    xBytesSent = xStreamBufferSendFromISR( xStreamBuffer,
                                           ( void * ) pcStringToSend,
                                           strlen( pcStringToSend ),
                                           \&xHigherPriorityTaskWoken );

    if( xBytesSent != strlen( pcStringToSend ) )
    \{
        // There was not enough free space in the stream buffer for the entire
        // string to be written, ut xBytesSent bytes were written.
    \}

    // If xHigherPriorityTaskWoken was set to pdTRUE inside
    // xStreamBufferSendFromISR() then a task that has a priority above the
    // priority of the currently executing task was unblocked and a context
    // switch should be performed to ensure the ISR returns to the unblocked
    // task.  In most FreeRTOS ports this is done by simply passing
    // xHigherPriorityTaskWoken into taskYIELD\_FROM\_ISR(), which will test the
    // variables value, and perform the context switch if necessary.  Check the
    // documentation for the port in use for port specific instructions.
    taskYIELD\_FROM\_ISR( xHigherPriorityTaskWoken );
\}
\end{DoxyPre}
 